package org.example;

import java.util.Arrays;

public class Test1 {
    //leetcode 445 分发饼干 https://leetcode.cn/problems/assign-cookies/description/

    /**
     * 饼干小的优先给胃口小的小孩
     * @param g
     * @param s
     * @return
     */
    public int findContentChildren(int[] g, int[] s) {
        if (s.length == 0) return 0;
        Arrays.sort(g);
        Arrays.sort(s);
        int ret = 0, index = 0;
        for (int i = 0; i < s.length && index < g.length; i++) {
            if (s[i] >= g[index]) {
                index++;
                ret++;
            }
        }
        return ret;
    }
}
